package com.dongdongshop.data;

import com.dongdongshop.enums.ResultEnums;

/*
* 统一返回类
* */
public class Result<T> {

    private Integer code;
    private String message;
    private T data;

    public Result() {
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }

    //成功返回
    public static Result OK(){
        return new Result(ResultEnums.SUCCESS.getNum(),ResultEnums.SUCCESS.getName());
    }

    //失败返回
    public static Result ER(){
        return new Result(ResultEnums.ERROR.getNum(),ResultEnums.ERROR.getName());
    }

    //通用方式
    public static Result response(ResultEnums em){
        return new Result(em.getNum(),em.getName());
    }
}
